package com.huangsm.book.designmodel.concurrentdatastructure;

import ch.qos.logback.core.util.TimeUtil;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


/**
 * 测试阻塞队列
 * @author huang
 * @date 2019/2/20
 */
public class BlockingQueueDemo {
    private static BlockingQueue queue=new ArrayBlockingQueue<>(40);
    private static ThreadPoolExecutor pool=new ThreadPoolExecutor(1,1,0L, TimeUnit.SECONDS ,queue);

    public static void producer(){
        try {
            queue.put("你好兄弟");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    public static void consumer(){
        Object   poll = queue.poll();
        System.out.println(poll);
    }

    public static void main(String[] args) {
        pool.execute(BlockingQueueDemo::producer);
        pool.execute(BlockingQueueDemo::consumer);
    }
}
